import java.text.SimpleDateFormat;
pipeline {

    agent {
        kubernetes {
            defaultContainer 'kaniko'
            yamlFile '../podTemplates/kaniko-executor-debug.yaml'
        }
    }

    environment {     
        DATED_GIT_HASH = "${new SimpleDateFormat("yyMMddHHmmss").format(new Date())}${GIT_COMMIT.take(6)}"    
    }

    stages {
        stage('Code Clone') {
            
            steps {
                echo "1. Clone Code Stage"
                git branch: 'master', url: 'https://gitee.com/zheng11581/cloudnative.git'
            }
        }   	    
        stage('Build with Kaniko') {	      
            steps {	    
                echo "2. Build with Kaniko"    
                container('kaniko') {	          
                    sh '/kaniko/executor \
                        --dockerfile $(pwd)/cncamp/httpserver/Dockerfile \
                        --context=$(pwd)/cncamp/httpserver \
                        --destination=asia-east2-docker.pkg.dev/sapient-duality-344101/httpserver:${DATED_GIT_HASH} \
                        --insecure \
                        --skip-tls-verify \
                        -v=debug'
                }	      
            }
                    	    
        } 

    }
}